package com.ftg.learn.chapter01;

/**
 * 快乐数
 *
 * @author lenovo
 * @version 1.0
 * @date 2023/5/13 15:46
 */

public class HappyNum {
    int a=19;
    public static boolean isHappy(int a){
        int sum=0;
        int n=0;
        while (sum!=1&&n<100000){
            int len=count(a);
            int temp=0;
            for(int i=0;i<len;i++){
                int a1 =a/(int)(Math.pow(10,i))%10;
                temp+=a1*a1;

            }
            a=temp;
            int f = a % 10;
            int s = a / 10 % 10;
            int t=a/100%10;
            sum = f * f + s * s+t*t;
            n++;
            if(n>=100){
                return false;
            }
        }
        return true;
    }
    public static  int count(int n){
        int index=0;
        while (n!=0){
            n/=10;
            index++;
        }
        return index;
    }
        public static void main(String[] args){
            System.out.println(isHappy(6789));



    }
}
